package com.loyal.loyalerp.basedata.department.utils.jsonserializer;

import java.io.IOException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.loyal.loyalerp.basedata.company.mapper.GyCompanyMapper;

@Component
public class CompanyIdJsonSerializer extends JsonSerializer<Integer> {

	@Autowired
	private GyCompanyMapper mapper;

	@Override
	public void serialize(Integer value, JsonGenerator gen, SerializerProvider serializers)
			throws IOException, JsonProcessingException {
		gen.writeString(mapper.selectByPrimaryKey(value).getCompanyname());
	}
}
